<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="jakarta.tags.core" %>
<%@ taglib prefix="fmt" uri="jakarta.tags.fmt" %>

<div class="admin-table">
    <table>
        <thead>
            <tr>
                <th>ID</th>
                <th>创建者</th>
                <th>爱人1</th>
                <th>爱人2</th>
                <th>开始日期</th>
                <th>可见性</th>
                <th>点赞数</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            <c:forEach items="${couples}" var="couple">
                <tr>
                    <td>${couple.id}</td>
                    <td>${couple.username}</td>
                    <td>
                        <a href="/couples/${couple.id}" target="_blank">
                        <img src="${empty couple.lover1_avatar ? '/static/images/default-avatar.jpg' : couple.lover1_avatar}" 
                             alt="${couple.lover1_name}" class="avatar-small">
                        ${couple.lover1_name}
                        </a>
                    </td>
                    <td>
                        <a href="/couples/${couple.id}" target="_blank">
                        <img src="${empty couple.lover2_avatar ? '/static/images/default-avatar.jpg' : couple.lover2_avatar}" 
                             alt="${couple.lover2_name}" class="avatar-small">
                        ${couple.lover2_name}
                        </a>
                    </td>
                    <td>${couple.formatted_start_date}</td>
                    <td>
                        <select class="visibility-select" data-id="${couple.id}">
                            <option value="1" ${couple.visibility == 1 ? 'selected' : ''}>公开</option>
                            <option value="0" ${couple.visibility == 0 ? 'selected' : ''}>私密</option>
                        </select>
                    </td>
                    <td>
                        <input type="number" class="likes-input" data-id="${couple.id}" 
                               value="${couple.likes}" min="0">
                    </td>
                    <td>
                        <button class="btn-small btn-primary" onclick="window.location.href='/admin/couples/${couple.id}/timeline'">时间线管理</button>
                        <button type="button" class="btn-small btn-primary" onclick="generateAISummary(${couple.id})">AI总结</button>
                        <button type="button" class="btn-small btn-danger" onclick="deleteCouple(${couple.id})">删除</button>
                    </td>
                </tr>
            </c:forEach>
        </tbody>
    </table>
</div>

<!-- AI总结编辑模态框 -->
<div id="aiSummaryModal" class="modal">
    <div class="modal-content">
        <h3>AI总结</h3>
        <form id="aiSummaryForm">
            <input type="hidden" name="coupleId">
            <div class="form-group">
                <label>总结内容</label>
                <textarea name="content" rows="10" style="width: 100%"></textarea>
            </div>
            <div class="form-actions">
                <button type="submit" class="btn-primary">发布为评论</button>
                <button type="button" onclick="closeModal('aiSummaryModal')" class="btn">取消</button>
            </div>
        </form>
    </div>
</div>

<script src="/static/js/admin-couples.js"></script> 

<!-- 加载遮罩 -->
<div class="loading-mask">
    <div class="loading-content">
        <div class="loading-spinner"></div>
        <span>AI正在生成总结中...</span>
    </div>
</div> 